class TextManager:
    def __init__(self, text_box, root):
        self.text_box = text_box
        self.root = root
    
    def insert_text_with_delay(self, text_list):
        """延迟插入文本列表"""
        self.text_box.delete(1.0, "end")  # 清空文本框
        if text_list:
            # 首先延迟一秒钟
            self.root.after(1000, lambda: self._insert_text_with_delay_helper(text_list))
        else:
            return

    def _insert_text_with_delay_helper(self, text_list):
        """延迟插入文本的辅助函数"""
        if text_list:
            self.text_box.insert("end", text_list[0] + "\n")
            self.text_box.see("end")  # 滚动到文本末尾
            # 从列表中移除已经插入的文本
            text_list.pop(0)
            # 延迟一秒钟后再次调用 _insert_text_with_delay_helper 函数，并传入更新后的文本列表
            self.root.after(1000, lambda: self._insert_text_with_delay_helper(text_list))
    
    def add_text_to_box(self):
        """向文本框添加文字"""
        self.text_box.insert("end", "Hello, world!\n") 